package dfs;

import java.lang.reflect.Array;
import java.util.Arrays;

public class 数独{
    public static void main(String[] args) {
        int table[][]=new int[3][3];
        dfs(table, 1, 2);
        print(table);
    }
    static void dfs(int[][] table,int x,int y){
        if(x==9){
            print(table);
            System.exit(0);
        }
        if(table[x][y]==0){
            for(int i=1;i<9;i++){
                boolean res=check(table,x,y,i);
                if(res){
                    table[x][y]=i;
                    dfs(table, x+(y+1)/9, (y+1)%9);
                }
                
            }
            table[x][y]=0;
        }else{
            dfs(table, x+(y+1)/9, (y+1)%9);
        }
        
    }
    static boolean check(int[][] table,int x,int y,int e){
        int count=0;
        e=table[x][y];
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++)
            if(table[i][j]==e)count++;
        }
        if(count==0){
            return true;
        }else return false;
    }
    static void print(int[][] table){
        for(int i=0;i<3;i++){
            System.out.print(table[i][0]+" ");
            System.out.print(table[i][1]+" ");
            System.out.print(table[i][2]+" ");
            System.out.println(" ");
        }
    }
}